package com.zr.corporatefactory.controller;

import com.sun.org.apache.regexp.internal.RE;
import com.zr.corporatefactory.model.*;
import com.zr.corporatefactory.service.CorFactoryService;
import com.zr.util.ErrorMessageClass;
import com.zr.util.ResultVo;
import com.zr.util.ResultVoBuilder;
import com.zr.util.StatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/12/24.
 */
@RestController
@CrossOrigin
public class CorFactoryController {

    @Autowired
    private CorFactoryService corFactoryService;

    @PostMapping("legalPlant/query")
    public ResultVo queryPage(@RequestBody PageSelectVo pageSelectVo){
        ResultVo resultVo = corFactoryService.getPage(pageSelectVo);

        return resultVo;
    }

   @GetMapping("legalPerson/ofCurrentUser")
    public ResultVo select(){
        /*List<Corporate> corList1 = corFactoryService.getPersonName();*/

       List<legalperson> corList = corFactoryService.getPersonName();
        /*List<PersonEnumVo> perList = new ArrayList<>();
        for (Corporate cor: corList) {
            PersonEnumVo pv = new PersonEnumVo();
            pv.setLegalPersonCode(cor.getLegalPersonCode());
            pv.setLegalPersonName(cor.getLegalPersonName());
            perList.add(pv);
        }*/

        return ResultVoBuilder.success(corList);
    }
     @PostMapping("legalPlant/add")
    public ResultVo addCorporate(@RequestBody @Valid CorAdd corAdd, BindingResult bindingResult){
         corAdd.setCfstatus(corAdd.getEnabled());

        corFactoryService.addCor(corAdd);
        return ResultVoBuilder.success("添加成功");
    }

    @PostMapping("legalPlant/update")
    public ResultVo update(@RequestBody @Valid CorUpdate corUpdate, BindingResult bindingResult){


        corUpdate.setCfstatus(corUpdate.getEnabled());

             corFactoryService.update(corUpdate);

             return ResultVoBuilder.success("修改成功");


    }

    @PostMapping("legalPlant/updatestatus")
    public ResultVo updateStatus(@RequestBody CorFacStatus corFacStatus){


        ResultVo resultVo = corFactoryService.updateStatus(corFacStatus);
        return resultVo;
    }
    @PostMapping("metadata/getPullDownLis")
    public ResultVo xiala(){
        List<StatusVo> statusVoList = new ArrayList<>();
        StatusVo statusVo = new StatusVo();
        statusVo.setLabel(StatusEnum.JINYONG.getValue());
        statusVo.setValue(StatusEnum.JINYONG.getName());
        statusVoList.add(statusVo);

        StatusVo statusVo2 = new StatusVo();
        statusVo2.setLabel(StatusEnum.QIYONG.getValue());
        statusVo2.setValue(StatusEnum.QIYONG.getName());
        statusVoList.add(statusVo2);

        StatusVo statusVo3 = new StatusVo();
        statusVo3.setLabel(StatusEnum.QUANBU.getValue());
        statusVo3.setValue(StatusEnum.QUANBU.getName());
        statusVoList.add(statusVo3);
        return ResultVoBuilder.success(statusVoList);
    }

}
